package com.pclong.doudizhu.server.demo1;
import java.util.*;

import java.util.List;

/**
 * Description:
 * </br>Copyright (C), 2005-2009, KK
 * </br>This program is protected by copyright laws.
 * </br>Program name: DouDiZhu
 * </br>Date: 12/10/09
 * @author kk
 * @version 1.0
 */

public class Player {
	private String name;
	private int score;
	private DDZCards cardsOnHand;
	// indicate the role of the player in the current round
	// 0: dizhu, -1: previous to dizhu, 1: after dizhu
	private int role;
	
	public Player () {}
	public Player (String name, int score)
	{
		this.name = name;
		this.score = score;
		this.cardsOnHand = new DDZCards();
		this.role = -1;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public int getScore()
	{
		return this.score;
	}
	
	public void setScore(int score)
	{
		this.score = score;
	}
	
	public void changeScore(int diff)
	{
		this.score += diff;
	}
	
	public void receiveCard(DDZPokerCard card)
	{
		this.cardsOnHand.addCard(card);
	}

	public DDZHandCards playCards(DDZHandCards lastTurn)
	{
		// TODO
		DDZHandCards nowTurn;
		
		nowTurn = Rules.findBigger(this.cardsOnHand, lastTurn, true);
		this.cardsOnHand.deleteCardAll(nowTurn.getDDZCards().getAllCards());
		
		return nowTurn;
	}
	
	// to call the dizhu or not
	public boolean call()
	{
		// TODO
		this.role = 0;
		return true;
	}
	
	public void setRole(int role)
	{
		if(role == 0 || role == -1 || role == 1)
			this.role = role;
	}
	
	public void beginRound()
	{
		// 1. sort the cards
		// 2. determine to call or not
	}
	
	public void endRound()
	{
		// 1. clear the on-hand cards
		// 2. store the history
	}
	
	public boolean joinGame(Game g, int seatID)
	{
		Seat[] s = g.getSeats();
		if(seatID>s.length-1)
			return false;
		else
		{
			return s[seatID].takenBy(this);
		}
	}
	
	public int getCardNum()
	{
		return cardsOnHand.getLength();
	}

	public void printCardsOnHand()
	{
		this.cardsOnHand.sort();
		System.out.print("Player "+this.name+" : ");
		this.cardsOnHand.print();
		System.out.print("\n");
	}
}
